<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page isELIgnored="false"%>
<jsp:include page="../frame/header.jsp"></jsp:include>

<title>租房管理</title>
<style>
div.in-line{
	margin-top:5px;
}
div.in-line label{
	width:70px;
	text-align:right;
}
#searchBtn{
	text-align:right;
}
#startArea{
	ime-mode: disabled;
}
</style>
</head>

<body>

	<div class="container-fluid">
		<div id="market" class="row-fluid">
			<div>
				<ul class="breadcrumb">
					<li><a href="#">实用功能</a> <span class="divider">/</span></li>
					<li><a href="#">租房管理</a></li>
				</ul>
			</div>

			<div class="box">
				<div class="box-header well" data-original-title>
					<h2>
						<i class="icon-th"></i> 房屋出租信息列表
					</h2>

					<div class="box-icon">
						<a href="#" class="btn btn-setting btn-round"><i
							class="icon-cog"></i></a> <a href="#"
							class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
						<a href="#" class="btn btn-close btn-round"><i
							class="icon-remove"></i></a>
					</div>
				</div>
				<div class="box-content">
					<div id="search-form">
						<form id="searchForm" method="post" class="form-search span12" action="<c:url value="/admin/func/search_rent"/>">
							<div class="in-line">
						<label>出租方式：</label>
						<select data-placeholder="不限" id="rentType" name="rentType" data-rel="chosen">
							<option value="0">不限</option>
							<option value="1">整租房</option>
							<option value="2">合租房</option>
							<option value="3">短租/日租</option>
							
						</select>
						<label>房屋类型：</label>
						<select data-placeholder="不限" id="houseType" name="houseType" data-rel="chosen">
							<option value="0">不限</option>
							<option value="1">House</option>
							<option value="2">Apartment</option>
							<option value="3">宿舍</option>
							
						</select>
						<label>发布类型：</label>
						<select class="input-medium" data-placeholder="不限" id="status" name="status" data-rel="chosen">
							<option value="0">不限</option>
							<option value="1">个人</option>
							<option value="2">经纪人</option>
							
						</select>
						</div>
						<div class="in-line">
						<label>标题：</label>
						<input class=""  name="title" id="title" 
										type="text" value="${searchForm.title }" >
						<label>联系人：</label>
						<input class=""  name="linkName" id="linkName" 
										type="text" value="${searchForm.linkName }" >
						<label>联系电话：</label>
						<input class="input-medium"  name="phone" id="phone" 
										type="text" value="${searchForm.phone }" >	
						</div>
						<div class="in-line">
						<label>出租面积：</label>
						<input class="input-small"  name="startArea" id="startArea" 
										type="text" value="${searchForm.startArea }" style="ime-mode:disabled">
										&nbsp;-&nbsp;
						<input class="input-small"  name="endArea" id="endArea" 
										type="text" value="${searchForm.endArea }" >										
						<label>每月租金：</label>
						<input class="input-small"  name="startPrice" id="startPrice" 
										type="text" value="${searchForm.startPrice }" >
										&nbsp;-&nbsp;
						<input class="input-small"  name="endPrice" id="endPrice" 
										type="text" value="${searchForm.endPrice }">	
						</div>
						
						<div class="in-line">
						<label>发布时间：</label>
						<input class="input-large datepicker"  name="startPublishDate" id="date1" 
										type="text" value="" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至：
						<input class="input-large datepicker" name="endPublishDate" id="date2" 
										type="text" value="" >
						<label></label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<button type="button" id="searchBtn" class="btn btn-success">&nbsp;&nbsp;搜索&nbsp;&nbsp;</button>
						
						</div>
						<div>
							<button type="button" id="newBtn" class="btn btn-danger pull-right">发布租房信息</button>
						</div>
						
							<input type="hidden" name="pageNum" id="pageNum" value="${searchForm.pageNum }">
							<input type="hidden" name="rentId" id="rentId" value="${searchForm.rentId }">
							
						</form>
						
					</div>
					<table id="userInfo" class="table table-striped table-bordered ">
						<thead>
							<tr>
								<th width=40>序号</th>
								<th width=70>出租类型</th>
								<th width=70>房屋类型</th>
								<th>标题</th>
								
								<th width=100>地址</th>
								
								<th width=60>联系人</th>
								<th width=80>联系电话</th>
								<th width=120>发布日期</th>
								<th width=60>操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach var="rent" items="${pageModel.result }" varStatus="status">
								<tr>
									<td>${status.index+1 }</td>
									
									<td>
										<c:choose>
											<c:when test="${rent.rentType == 1 }">
												整租房
											</c:when>
											<c:when test="${rent.rentType == 2 }">
												合租房
											</c:when>
											<c:otherwise>
												短租/日租
											</c:otherwise>
										</c:choose>
									</td>
									<td>
										<c:choose>
											<c:when test="${rent.houseType == 1 }">
												house
											</c:when>
											<c:when test="${rent.houseType == 2 }">
												flat
											</c:when>
											<c:otherwise>
												宿舍
											</c:otherwise>
										</c:choose>
									</td>
									<td>${rent.title}  </td>
									<td>${rent.address }</td>
									<td>${rent.linkName }</td>
									<td>${rent.phone }</td>
									<td>${rent.publishDate }</td>
									<td><a href="javascript:edit('${rent.rentId }')"><i
											class="icon-edit"></i></a> &nbsp;&nbsp; <a
										href="javascript:del('${rent.rentId }')"><i class="icon-minus"></i></a></td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					
					<div id="mypager" class="mypager"></div>
				</div>
			</div>
		</div>
		<!--/fluid-row-->

	</div>
	<!--/.fluid-container-->

	<jsp:include page="../frame/scripts.jsp"></jsp:include>
	<script type="text/javascript">
	var pageNum = "${pageModel.pageNum}";
	var totalPage = "${pageModel.totalPage}";
	var numPerPage = "${pageModel.numPerPage}";
	
	$(document).ready(function(){
		
		$("#searchForm").validation();
		
		$("#newBtn").click(function(){
			//跳转至新增页面
			window.location.href = '<c:url value="/admin/func/addRent" />';
		})
		
		$('.datepicker').datepicker('option', 'dateFormat', 'yy-mm-dd'); 
	    $( "#date1" ).datepicker( "setDate", "${searchForm.startPublishDate}" );
	    $( "#date2" ).datepicker( "setDate", "${searchForm.endPublishDate}" );
		
		$("#rentType").val(${searchForm.rentType});
		$("#houseType").val(${searchForm.houseType});
		$("#status").val(${searchForm.status});
		
		$('#mypager').bootstrapPaginator({
			currentPage:pageNum,
			totalPages:totalPage,
			numberOfPages:numPerPage,
			onPageClicked:function(event, originalEvent, type,page){
				$("input[name='pageNum']").val(page);
				$("#searchForm").submit();
			}
		});
		
		$('#searchBtn').click(function(){
			replace("startArea");
			replace("endArea");
			replace("startPrice");
			replace("endPrice");
			$("#searchForm").submit();
		})
		
		$("#startArea,#endArea,#startPrice,#endPrice").keydown(function(event) {
			var keyCode = event.keyCode;
			return (keyCode == 46 || (keyCode >= 48 && keyCode <=57) || keyCode == 8)//8是删除键
		}).focus(function() {
			
		}).on("paste",function(){
			return false;
		});
	})
	
	function replace(id){
		var obj = $("#"+id);
		if(obj.val() == ''){
			obj.val(0);	
		}
	}
	
	function edit(rentId){
		window.location.href = '<c:url value="/admin/func/editRent?rentId='+rentId+'"/>';
	}
	
	function del(rentId){
		if(confirm("确定要删除吗？")){
			$("input[name='rentId']").val(rentId);
			$("#searchForm").submit();
		}
	}
	
	
	</script>
</body>
</html>
